package com.brooks.demo;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 线程的创建方式
 * @Author mihutu
 * @Date 2020/10/16 09:58
 * @Version 1.0
 */
public class DemoThread3 {
        static class MyThread extends Thread{
            @Override
            public void run() {
                System.out.println("myThread");
            }
        }
        static class MyRun implements Runnable{
            @Override
            public void run() {
                System.out.println("myRun");
            }
        }
        static class MyCall implements Callable<String>{
            @Override
            public String call() throws Exception {
                return "myCall";
            }
        }
       public static void main(String[] args) {
            new MyThread().start();
            new Thread(new MyRun()).start();
            new Thread(()->{
                System.out.println("lamda");
            }).start();
           FutureTask<String> ft = new FutureTask<String>(new MyCall());
            new Thread(ft).start();
           try {
               System.out.println(ft.get());
           } catch (InterruptedException e) {
               e.printStackTrace();
           } catch (ExecutionException e) {
               e.printStackTrace();
           }
       }
}